Imports ValidationFramework.Configuration
Imports ValidationFramework
Imports NUnit.Framework

Namespace NewRule
    <TestFixture()> _
    Public Class RequiredCharacterRuleConfigReaderUsage


        Public Class Person

            Private _name As String

            Public Property Name() As String
                Get
                    Return _name
                End Get
                Set(ByVal value As String)
                    _name = value
                End Set
            End Property

        End Class



        Private ReadOnly propertyXmlString As String = "<?xml version='1.0' encoding='utf-8' ?>" & _
                                                       "<validationMapping xmlns='urn:validationFramework-validationDefinition-1.5'>" & _
                                                       "  <class typeName='ExampleLibraryVB.NewRule.RequiredCharacterRuleConfigReaderUsage+Person, ExampleLibraryVB'>" & _
                                                       "    <property name='Name'>" & _
                                                       "      <rule typeName='ExampleLibraryVB.NewRule.RequiredCharacterRuleConfigReader, ExampleLibraryVB' requiredCharacter='s'/>" & _
                                                       "    </property>" & _
                                                       "  </class>" & _
                                                       "</validationMapping>"

        <Test()> _
        Public Sub Run()

            Dim person As New Person
            Dim s As String
            s = person.GetType().FullName
            ConfigurationService.AddXmlString(propertyXmlString)
            Dim propertyValidationManager As New PropertyValidationManager(person)

            propertyValidationManager.Validate("Name")
            ' Valid dinosaur.Name is Null
            Assert.IsTrue(propertyValidationManager.IsValid)

            person.Name = "john"
            propertyValidationManager.Validate("Name")
            ' Invalid because Name does not contain 's'
            Assert.IsFalse(propertyValidationManager.IsValid)

            person.Name = "simon"
            propertyValidationManager.Validate("Name")
            ' Valid because Name does contain 's'
            Assert.IsTrue(propertyValidationManager.IsValid)
        End Sub

    End Class
End Namespace